#include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Solution
{
private:
    static bool cmp(std::pair<int, vector<int>> &a, std::pair<int, vector<int>> &b)
    {
        return a.first < b.first;
    }

public:
    vector<vector<int>> kClosest(vector<vector<int>> &points, int k)
    {
        std::priority_queue<std::pair<int, vector<int>>, vector<std::pair<int, vector<int>>>, decltype(&Solution::cmp)> pq(&Solution::cmp);
        for (auto p : points)
        {
            int dist = p[0] * p[0] + p[1] * p[1];
            pq.push(std::pair(dist, p));
            if (pq.size() > k)
                pq.pop();
        }
        vector<vector<int>> res;
        while (!pq.empty())
        {
            res.push_back(pq.top().second);
            pq.pop();
        }
        return res;
    }
};

int main()
{
    cout << "Code973" << endl;
    Solution s;
    vector<vector<int>> points = {{3, 3}, {5, -1}, {-2, 4}};
    int k = 2;
    vector<vector<int>> res = s.kClosest(points, k);
    for (auto p : res)
    {
        cout << "(" << p[0] << ", " << p[1] << ")" << endl;
    }
    return 0;
}